home *** CD-ROM | disk | FTP | other *** search
/ Hackers Underworld 2: Forbidden Knowledge / Hackers Underworld 2: Forbidden Knowledge.iso / VIRUS / VIRUS101.002 < prev    next >
Internet Message Format  |  1994-07-17  |  18KB

  1. From: woodside@ttidca.TTI.COM (George Woodside)
  2. Newsgroups: comp.sys.atari.st,comp.sys.apple,comp.sys.mac,comp.sys.ibm.pc
  3. Subject: Virus 101 - Chapter 2
  4. Date: 6 Mar 89 14:00:21 GMT
  5.  
  6. In response to a lot of the mail I've received:
  7. 1) You haven't missed the "rest of the chapters". I'm posting them as I
  8.    get them written.
  9.  
  10. 2) You may not agree with me. I tried to set down the definitions and
  11.    terms as I would be using them, for the benefit of those who weren't
  12.    familiar with them. This whole area is rather vague, and most of us
  13.    in the trenches and making up the rules, as we learn the game.
  14.  
  15. When we left our virus at the end of Chapter 1, it had managed to get
  16. itself installed in our system by being present on the boot sector of a
  17. disk in the machine at cold start or reset. 
  18.  
  19. Another way a virus may be installed is via a trojan horse program. Trojan
  20. horses come in many flavors. Some disguise themselves as programs which
  21. provide some useful function or service, while secretly doing something
  22. else. The something else may be installing a virus, sabotaging some part of
  23. a disk, setting up hooks to steal passwords on time sharing systems, or
  24. whatever else you can imagine. In the event of the virus installer, the
  25. trojan horse has a bit more flexibility than a typical boot sector virus,
  26. simply because it doesn't have to fit itself into a relatively small space.
  27. Since it is hiding in a larger program, it can be whatever size is
  28. necessary to accomplish the task. 
  29.  
  30. A typical boot sector contains information about the layout of the disk it
  31. resides upon. This block of data requires 26 bytes. The first three bytes
  32. of the boot sector are left available for an assembly language "jump"
  33. command, to allow the execution of the code to skip over the boot sector's
  34. data block. And, the boot sector must add up to the proper magic number to
  35. have executable status. That will require another two bytes, since the
  36. checksum is a 16 bit value. So, 31 bytes are allocated. Since (at least in
  37. the 68000 family) machine instructions are always 16 bits and must begin on
  38. an even address, 32 of the 512 bytes in the boot sector are not available
  39. to any executable program. So, there are 480 bytes available for the
  40. executable code. Machine instructions vary in length, depending upon what
  41. they do, and how much additional information is required. In the 68000,
  42. instruction lengths vary from one to five words, but a reasonable average
  43. instruction length for a program is just over two words. That translates
  44. the 480 bytes to 120 instructions. 
  45.  
  46. The virus must contain the code to install itself, reserve the memory it
  47. occupies to keep subsequent programs from over-writing it, spread itself to
  48. other disks, and whatever it really intends to do once it decides it is
  49. time to act. That's quite a bit of code to fit into 120 instructions,
  50. unless it extends itself by loading some other part of the disk, or a file. 
  51.  
  52. Files are pretty much out of the question. Most computer users would notice
  53. if some file they didn't recognize started popping up on a lot of their
  54. disks. There are attributes settable in a disk directory which can be used
  55. to tell the operating system that certain files are "Hidden" or "System"
  56. files. If the file had the proper status bits set, it could prevent itself
  57. from appearing in normal disk directory displays. There are, however, more
  58. flexible disk directory listing programs which will display the entries for
  59. these files, as well as normal files. There is also the problem of the
  60. space the hidden file occupies, as well as the directory entry. The space
  61. available on the disk will be less than it should be, since the hidden file
  62. is present. These symptoms would not escape detection for long. 
  63.  
  64. A more effective method is the use of specific disk sectors. The standard
  65. disk layout covered in the preceeding chapter mentioned such things as File
  66. Allocation Tables, and disk directory space. In a standard format Atari
  67. disk, for example, each FAT is 5 sectors long, and the directory is 7
  68. sectors long. That is more than enough FAT space to accomodate the entire
  69. disk. A virus in need of more space than 480 bytes might write the
  70. remainder of itself in the last sector of the FAT (I have one that does
  71. this). It might also write itself in the last sector of the directory,
  72. taking advantage of a quirk in the operating system. 
  73.  
  74. When a disk is formatted, all data sectors are normally filled with a
  75. pre-defined value, E5 (hexadecimal). The directory and FAT space is usually
  76. set to 00. When a directory entry is made active, the file name is written
  77. in the directory, along with some other required information. When a file
  78. is deleted, the first byte of the directory entry is set to E5. That makes
  79. the entry available again. This is a carry over from the early days of
  80. floppy disks, when where the directory would exist on a disk was not as
  81. well defined. The directory entries had to appear as empty on a freshly
  82. formatted disk, so E5 was used as a deleted entry mark. That way, no matter
  83. where the directory was, a freshly formatted disk would always appear as
  84. empty. Now, since disk formats are more flexible, the directory is located
  85. by parameters, and normally the entire directory space is zeroed at
  86. formatting time. Since an active entry will have some legitimate ASCII
  87. character in the beginning of the file name, and a deleted entry will have
  88. E5 in the first byte, it is generally assumed that encountering a directory
  89. entry with a value of 00 in the first byte indicates that the entry has
  90. never been used. Since directory entries are used (and deleted ones
  91. re-used) on a first-found basis, finding one with 00 means that not only
  92. has it not been used, but none of the ones following it will have been used
  93. either. Consequently, most software stops looking at the directory entries
  94. when a 00 entry pops up. If there are several more sectors available, there
  95. may be something hiding out there, beyond the last used entry. While this
  96. method of hiding is not foolproof, the typical virus is not concerned about
  97. being bulletproof in all cases. It just has to survive long enough to
  98. reproduce itself, and it has half the battle won. As long as it keeps
  99. spreading, sooner or later it will survive long enough to do the task it is
  100. designed to do, then it wins both halves of the battle. 
  101.  
  102. There are other ways for the virus to get additional disk space. Typically,
  103. floppy disks are not used up a sector at a time, but rather in groups of
  104. sectors. Each group of sectors is referred to as a data "cluster". The
  105. number of sectors in a cluster is variable, and is one of the parameters
  106. stored in the boot sector. If the number of data sectors on the entire
  107. disk, minus the boot sector, FATs, and directory, is not an exact multiple
  108. of the number of sectors in a data cluster, the remaining sectors will
  109. never be used by the opearting system. A clever virus can find them and
  110. hide there. The inconvenience of this is that the unused sectors would
  111. normally be at the end of the last track of the disk, causing long (and
  112. noticeable) disk seeks to load or spread the virus. 
  113.  
  114. There is a parameter in the boot sector designed to permit the disk to have
  115. sectors reserved for any purpose, and not accessed as part of the normal
  116. data area. A virus could also use this method to extend itself, but it,
  117. too, has shortcomings. Using this feature requires the parameter to be set
  118. when the disk has absolutely no data on it. Reserving sectors causes the
  119. start of the data area to be moved further into the disk. While the data
  120. area would be moved, the data already on the disk would not. Consequently,
  121. altering the reserved sectors parameter would make all files on the disk
  122. garbage. (They could be returned to proper status by restoring the original
  123. value to the reserved sectors parameter, providing no disk write had
  124. occurred.) There would also be the problem of the disk's free space being
  125. less that it should. 
  126.  
  127. Consequently, if a virus needs extra space, using prescribed system
  128. features or hidden files is not a good choice, since it is too easily
  129. detected. The approach used so far is to hide in sectors unlikely to be
  130. used, and hope to spread before they get clobbered